package model.protocal
{
	import com.adobe.serialization.json.JSON;
	import com.google.maps.LatLng;
	
	import model.protocal.base.IProtocol;
	
	import mx.logging.ILogger;
	
	import utils.LogUtil;
	
	import view.MapCanvas;
	
	public class GpsInvalid_lbs_protocal implements IProtocol
	{
		public static var NAME : String = "GpsInvalid_lbs_protocal.as";
		private var logger:ILogger =  LogUtil.getInst().getLogger( NAME );
		protected var protocalString:String = Global.SERVER_DEVICE_URL + "?action=interface-lbs&cid={0}&lac={1}";
//		private var context:TrackerContext;
		private var _data:Object;
		private var _callback:Function;
		
		public function GpsInvalid_lbs_protocal(lac:String, cid:String, data:Object, callback:Function)
		{
			setProtocal(cid, lac);
//			this.context = context;
			_data = data;
			_callback = callback;
		}
		
		public function getProtocalString():String
		{
			return protocalString;
		}
		
		public function setProtocal(cid:String, lac:String):void
		{
			this.protocalString = protocalString.replace("{0}", cid).replace("{1}", lac);
		}
		
		public function onResponseHandler(evt:Object):void
		{
			logger.info("返回..." + evt.target.data);
			var respData:Object = JSON.decode(evt.target.data);
			if ( _data != null && respData.status == 1)
			{
				var data:Object = respData.data;
//				var endLatLng:LatLng = new LatLng(data.map.latitude, data.map.longitude);
				if(_callback!=null)
				{
					_data.latitude = data.map.latitude;
					_data.longitude = data.map.longitude;
					_callback(_data);
					_callback = null;
				}
				
//				var mapCanvas:MapCanvas = this.context.mapCanvas;
//				mapCanvas.setMarker(endLatLng);	
			} else {
				logger.error("获取mapCanvas失败!,respData.status!=1");			
			}
		}
	}
}